import { defineStore } from 'pinia'
import { getLoginUserApi } from '@/api/user'

export const useStore = defineStore('main', {
    state: () => {
        return {
            token: '',
            loginUser: {
                username: "未登录",
				role: ''
            },
			theme: 'light'
        }
    },
    actions: {
        //后台请求登录接口
        async getLoginUser() {
			console.log('store登录')
            // 从远程请求获取登录信息
			const res = await getLoginUserApi()
			console.log(res)
			if(res.code===0){
				console.log(this.loginUser)
				this.loginUser.username = res.data?.user?.username
				this.loginUser.role = res.data?.user?.role
			}else{
				this.loginUser.username = "未登录"
				this.loginUser.role = ''
			}
        }
    },
    unistorage: true
})